﻿<AddDataFormTemplateSpec 
	xmlns="bb_appfx_adddataformtemplate"
	xmlns:common="bb_appfx_commontypes" 
	ID="51d061f9-cea5-42a0-936a-1fe609e988ac" 
	Name="FundraisingPurpose Add Data Form"
	Description="REPLACE_WITH_DESCRIPTION" 
	Author="Blackbaud Product Development"
	DataFormInstanceID="f60ecc26-1ac1-461d-a6b4-d7829a9eeda4" 
	RecordType="REPLACE_WITH_RECORD_TYPE"
	common:SecurityUIFolder="REPLACE_WITH_SECURITYUIFOLDER"
	>

	<SPDataForm>
		<!-- describe the preload SP (if applicable), which should be used to fetch field default values from the database.  If no
		preload is needed, then this section can be removed -->
		<LoadImplementation SPName="USP_DATAFORMTEMPLATE_ADD_xxx_PRELOAD">
			<common:CreateProcedureSQL>
				<![CDATA[
create procedure dbo.USP_DATAFORMTEMPLATE_ADD_xxx_PRELOAD
(
	@CONTEXTID uniqueidentifier,
	@FIELD1 nvarchar(10) = null output
)
as
	set nocount on;
		
	-- populate the fields that have default values that should be fetched from the database
	select @FIELD1 = FIELD1
	from dbo.SOMETABLE
	where ID = @CONTEXTID
	
	return 0;				
				]]>
			</common:CreateProcedureSQL>
		</LoadImplementation>

		<!-- describe the save SP -->
		<SaveImplementation SPName="USP_DATAFORMTEMPLATE_ADD_xxx">
			<common:CreateProcedureSQL>
				<![CDATA[
create procedure dbo.USP_DATAFORMTEMPLATE_ADD_xxx
(
    @ID uniqueidentifier = null output,
	@CONTEXTID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
	@FIELD1 nvarchar(10) = '',
	@FIELD2 nvarchar(20) = '',
	@FIELD3 nvarchar(max) = ''
)
as

set nocount on;

if @ID is null
    set @ID = newid()

if @CHANGEAGENTID is null  
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()

begin try
	-- handle inserting the data
	insert into dbo.TABLE1
		(ID, FIELD1, FIELD2, FIELD3, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
    values
		(@ID, @FIELD1, @FIELD2, @FIELD3, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)
	
end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0				
				]]>
			</common:CreateProcedureSQL>
		</SaveImplementation>
	</SPDataForm>

	<!-- describe the context ID for this form (if applicable), which corresponds to a parameter in the SP. -->
	<Context ContextRecordType="REPLACE_WITH_RECORDTYPE" RecordIDParameter="CONTEXTID"/>

	<!-- describe fields on the form, which correspond to parameters on the SP.  Note that system parameters 
	like the context @ID, @CONTEXTID, and @CURRENTAPPUSERID need not be listed. -->
	<common:FormMetaData FixedDialog="true">
		<common:FormFields>
			<common:FormField FieldID="FIELD1" Caption="Field 1" DataType="String" MaxLength="10" />
			<common:FormField FieldID="FIELD2" Caption="Field 2" DataType="String" MaxLength="20" />
			<common:FormField FieldID="FIELD3" Caption="Field 3" DataType="String" />
		</common:FormFields>

		<!-- indicate the client-side component for the user interface -->
		<common:FormUIComponent FormUIComponentType="CustomComponent">
			<common:CustomComponentID AssemblyName="REPLACE_WITH_ASSEMBLYNAME" ClassName="REPLACE_WITH_FULLCLASSNAME" />
		</common:FormUIComponent>
	</common:FormMetaData>

</AddDataFormTemplateSpec>